package com.shijichaoxing.utils;

import java.util.List;

public class PageParam<T> {

    private int currPage = 1;

    private int totalPage = 1;

    private int rowCount = 1;

    private int pageSize = 10;

    private List<T> data;

    public int getCurrPage() {
        return currPage;
    }

    public void setCurrPage(int currPage) {
        this.currPage = currPage < 1 ? 1 : currPage;
    }

    public int getTotalPage() {
        return totalPage;
    }

    public void setTotalPage(int totalPage) {
        this.totalPage = totalPage;
    }

    public int getRowCount() {
        return rowCount;
    }

    public void setRowCount(int rowCount) {
        if (rowCount < 1) {
            rowCount = 0;
        }
        int totalPage = rowCount / pageSize;
        if (rowCount % pageSize > 0) {
            totalPage++;
        }
        setTotalPage(totalPage);
        this.rowCount = rowCount;
    }

    public int getPageSize() {
        return pageSize;
    }

    public void setPageSize(int pageSize) {
        this.pageSize = pageSize < 1 ? 1 : pageSize;
    }

    public List<T> getData() {
        return data;
    }

    public void setData(List<T> data) {
        this.data = data;
    }

    public PageParam() {
    }

    public PageParam(int currPage, int pageSize) {
        this.setCurrPage(currPage);
        this.setPageSize(pageSize);
    }

    @Override
    public String toString() {
        final StringBuffer sb = new StringBuffer("PageParam{");
        sb.append("currPage=").append(currPage);
        sb.append(", totalPage=").append(totalPage);
        sb.append(", rowCount=").append(rowCount);
        sb.append(", pageSize=").append(pageSize);
        sb.append(", data=").append(data);
        sb.append('}');
        return sb.toString();
    }

}
